package com.lsfb.signsys.bootstrap;

import android.support.annotation.NonNull;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Created by zgscwjm on 2018/3/22.
 */

public class BootstrapPresenter implements BootstrapContract.Presenter {

    @NonNull
    private final BootstrapContract.View mBootstrapView;
    private final CompositeDisposable mCompositeDisposable;

    public BootstrapPresenter(BootstrapContract.View BootstrapView) {
        //将视图层 注入到 控制层
        this.mBootstrapView = BootstrapView;

        //用于防止内存泄漏
        mCompositeDisposable = new CompositeDisposable();

        //这一步很关键,将控制层 注入到 视图层里面
        mBootstrapView.setPresenter(this);
    }

    @Override
    public void subscribe() {
        startCountdown();
    }

    @Override
    public void unsubscribe() {
        //回收内存
        mCompositeDisposable.clear();
    }


    @Override
    public void startCountdown() {
        mCompositeDisposable.clear();
        Disposable disposable = Observable.timer(5, TimeUnit.SECONDS).subscribe(__ -> mBootstrapView.showMainActivity());
        mCompositeDisposable.add(disposable);
    }
}
